package personnel.department.pages.addpage;

import java.util.List;
import java.util.Set;

import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.TabFolder;

import personnel.department.dao.entity.Retraining;
import personnel.department.pages.PDTable;

public class RetrainingEditor extends AbstractTableEditor<Retraining> {

	public RetrainingEditor(CTabFolder tabFolder) {
		super(tabFolder, "Переподготовка");
	}
	
	public RetrainingEditor(CTabFolder tabFolder, Set<Retraining> retrainings) {
		super(tabFolder, "Переподготовка", retrainings);
	}

	@Override
	public PDTable<Retraining> createTable(Composite parent) {
		return new PDTable<Retraining>(parent) {

			@Override
			public List<Retraining> setModelProvider() {
				return getModel();
			}

			@Override
			protected void createColumns(Composite parent, TableViewer viewer) {
				String[] titles = { "Специальность", "Дата"};
				int[] bounds = { 150, 100};

				TableViewerColumn col = createTableViewerColumn(getViewer(), titles[0], bounds[0], 0);
				col.setLabelProvider(new ColumnLabelProvider() {
					@Override
					public String getText(Object element) {
						Retraining e = (Retraining) element;
						return String.valueOf(e.getSpeciality());
					}
				});

				col = createTableViewerColumn(getViewer(), titles[1], bounds[1], 1);
				col.setLabelProvider(new ColumnLabelProvider() {
					@Override
					public String getText(Object element) {
						Retraining e = (Retraining) element;
						return format.format(e.getDateRetraining());
					}
				});
			}
		};
	}

}
